home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / sendmail / sendmail-5.65 / src / stab.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-05  |  2.7 KB  |  122 lines

  1. /*
  2.  * Copyright (c) 1983 Eric P. Allman
  3.  * Copyright (c) 1988 Regents of the University of California.
  4.  * All rights reserved.
  5.  *
  6.  * Redistribution and use in source and binary forms are permitted provided
  7.  * that: (1) source distributions retain this entire copyright notice and
  8.  * comment, and (2) distributions including binaries display the following
  9.  * acknowledgement:  ``This product includes software developed by the
  10.  * University of California, Berkeley and its contributors'' in the
  11.  * documentation or other materials provided with the distribution and in
  12.  * all advertising materials mentioning features or use of this software.
  13.  * Neither the name of the University nor the names of its contributors may
  14.  * be used to endorse or promote products derived from this software without
  15.  * specific prior written permission.
  16.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  17.  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  18.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  19.  */
  20.  
  21. #ifndef lint
  22. static char sccsid[] = "@(#)stab.c    5.7 (Berkeley) 6/1/90";
  23. #endif /* not lint */
  24.  
  25. # include "sendmail.h"
  26.  
  27. /*
  28. **  STAB -- manage the symbol table
  29. **
  30. **    Parameters:
  31. **        name -- the name to be looked up or inserted.
  32. **        type -- the type of symbol.
  33. **        op -- what to do:
  34. **            ST_ENTER -- enter the name if not
  35. **                already present.
  36. **            ST_FIND -- find it only.
  37. **
  38. **    Returns:
  39. **        pointer to a STAB entry for this name.
  40. **        NULL if not found and not entered.
  41. **
  42. **    Side Effects:
  43. **        can update the symbol table.
  44. */
  45.  
  46. # define STABSIZE    400
  47.  
  48. static STAB    *SymTab[STABSIZE];
  49.  
  50. STAB *
  51. stab(name, type, op)
  52.     char *name;
  53.     int type;
  54.     int op;
  55. {
  56.     register STAB *s;
  57.     register STAB **ps;
  58.     register int hfunc;
  59.     register char *p;
  60.     extern char lower();
  61.  
  62.     if (tTd(36, 5))
  63.         printf("STAB: %s %d ", name, type);
  64.  
  65.     /*
  66.     **  Compute the hashing function
  67.     **
  68.     **    We could probably do better....
  69.     */
  70.  
  71.     hfunc = type;
  72.     for (p = name; *p != '\0'; p++)
  73.         hfunc = (((hfunc << 7) | lower(*p)) & 077777) % STABSIZE;
  74.  
  75.     if (tTd(36, 9))
  76.         printf("(hfunc=%d) ", hfunc);
  77.  
  78.     ps = &SymTab[hfunc];
  79.     while ((s = *ps) != NULL && (strcasecmp(name, s->s_name) || s->s_type != type))
  80.         ps = &s->s_next;
  81.  
  82.     /*
  83.     **  Dispose of the entry.
  84.     */
  85.  
  86.     if (s != NULL || op == ST_FIND)
  87.     {
  88.         if (tTd(36, 5))
  89.         {
  90.             if (s == NULL)
  91.                 printf("not found\n");
  92.             else
  93.             {
  94.                 long *lp = (long *) s->s_class;
  95.  
  96.                 printf("type %d val %lx %lx %lx %lx\n",
  97.                     s->s_type, lp[0], lp[1], lp[2], lp[3]);
  98.             }
  99.         }
  100.         return (s);
  101.     }
  102.  
  103.     /*
  104.     **  Make a new entry and link it in.
  105.     */
  106.  
  107.     if (tTd(36, 5))
  108.         printf("entered\n");
  109.  
  110.     /* make new entry */
  111.     s = (STAB *) xalloc(sizeof *s);
  112.     bzero((char *) s, sizeof *s);
  113.     s->s_name = newstr(name);
  114.     makelower(s->s_name);
  115.     s->s_type = type;
  116.  
  117.     /* link it in */
  118.     *ps = s;
  119.  
  120.     return (s);
  121. }
  122.